/*
 * @Author: wangc
 * @Date: 2020-08-22 10:37:32
 * @LastEditTime: 2020-08-22 12:24:04
 * @Description: 
 */
package com.example.service;

import java.util.Date;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.example.model.User;

import org.springframework.stereotype.Service;
/**
 * 获取token
 */
@Service
public class TokenService {

	public String getToken(User user) {
		Date start = new Date();
		long currentTime = System.currentTimeMillis() + 60* 60 * 1000;//一小时有效时间
		Date end = new Date(currentTime);
		String token = "";
		
		token = JWT.create().withAudience(user.getId()).withIssuedAt(start).withExpiresAt(end)
				.sign(Algorithm.HMAC256(user.getPassword()));
		return token;
	}
}